package com.tham.dao;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import oracle.jdbc.OracleTypes;
import org.apache.log4j.Logger;
import utiles.AppProperties;
import utiles.ConexionPool;

import com.fic.dto.CtrlMedicaDTO;
import com.tham.dto.HoraDisponibleDTO;
import com.tham.dto.ListaUrgenteDTO;
import com.tham.dto.ReservaDTO;
import com.tham.vo.ReservaVO;
import com.tham.vo.ReservaVOLE;
import com.tham.vo.ReservaVORA;

public class ReservaDAO {
	private static Logger log = Logger.getLogger(ReservaDAO.class);
	String pkgVar = (AppProperties.getProperty("aplicacion", "PACKAGE"));
	
	public List<HoraDisponibleDTO> getAgendaEntidad(String fecha, String idProf) throws SQLException, IOException{
		////ConexionPool connDao = new ConexionPool();
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    					    
        int semamanNum = 0;
        String horaSet = "0";

		List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.getAgendaEntidad(?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, fecha);
			stmt.setString(2, idProf);
			stmt.registerOutParameter(3, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(3);

			while (rs.next()) {
				HoraDisponibleDTO comDTO = new HoraDisponibleDTO();
				comDTO.setIdRangoAgenda(rs.getString(1));
				comDTO.setIdDiaSemana(rs.getString(2));	
				comDTO.setDiaSemana(rs.getString(3));
				comDTO.setIdAgendaPrg(rs.getString(4));
				comDTO.setIdEstadoAg(rs.getString(5));
				comDTO.setDescrEstadoAg(rs.getString(6));
				comDTO.setHoraCita(rs.getString(7));
				comDTO.setFecCita(rs.getString(8));
				if (horaSet.equals(rs.getString(7))){
					comDTO.setSemanaNum( Integer.toString(semamanNum));
				}else{
					horaSet = rs.getString(7);
					semamanNum++;
					comDTO.setSemanaNum( Integer.toString(semamanNum));					 
				}
				comDTO.setIdProducto(rs.getString(9));
				listAgenda.add(comDTO);
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getAgendaEntidad SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}	
	
	public List<HoraDisponibleDTO> setAgendaReserva(ReservaVO resVO) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		/*
		System.out.println("prg "+resVO.getIdAgendaPrg()+" pac:"+resVO.getIdPaciente()+" cant:"+
				resVO.getCantHoras()+" urg:"+resVO.getUrgenteSN()+" tipo:"+resVO.getIdTipoPac()+" user:"+resVO.getIdUser()+" ser:"+
				resVO.getIdServicio()+" obs:"+resVO.getObservacion()+" conf:"+resVO.getConfReag());
				*/

		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    						    
		int idMovimiento = 0;

		List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.setAgendaReserva(?,?,?,?,?,?,?,?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, resVO.getIdAgendaPrg());
			stmt.setString(2, resVO.getIdPaciente());
			stmt.setString(3, resVO.getCantHoras());
			stmt.setString(4, resVO.getUrgenteSN());
			stmt.setString(5, resVO.getIdTipoPac());
			stmt.setString(6, resVO.getIdUser());
			stmt.setString(7, resVO.getIdServicio());
			stmt.setString(8, resVO.getObservacion());
			stmt.setString(9, resVO.getIdAgReserv());
			stmt.registerOutParameter(10, OracleTypes.INTEGER);					
			stmt.execute();
			HoraDisponibleDTO agenReservDTO = new HoraDisponibleDTO();
			idMovimiento = (stmt.getInt(10)); 		
			agenReservDTO.setIdAgendaReserva(String.valueOf(idMovimiento));
			listAgenda.add(agenReservDTO);
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getAgendaEntidad SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}	
	
	public List<HoraDisponibleDTO> setAgendaReservaLE(ReservaVOLE resVO) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		/*
		System.out.println("prg "+resVO.getIdAgendaPrg()+" pac:"+resVO.getIdPaciente()+" cant:"+
				resVO.getCantHoras()+" urg:"+resVO.getUrgenteSN()+" tipo:"+resVO.getIdTipoPac()+" user:"+resVO.getIdUser()+" ser:"+
				resVO.getIdServicio()+" obs:"+resVO.getObservacion()+" conf:"+resVO.getConfReag());
		 */
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    						    
		int idMovimiento = 0;

		List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.setAgendaReserva(?,?,?,?,?,?,?,?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, resVO.getIdAgendaPrg());
			stmt.setString(2, resVO.getIdPaciente());
			stmt.setString(3, resVO.getCantHoras());
			stmt.setString(4, resVO.getUrgenteSN());
			stmt.setString(5, resVO.getIdTipoPac());
			stmt.setString(6, resVO.getIdUser());
			stmt.setString(7, resVO.getIdServicio());
			stmt.setString(8, resVO.getObservacion());
			stmt.setString(9, "");
			stmt.registerOutParameter(10, OracleTypes.INTEGER);					
			stmt.execute();
			HoraDisponibleDTO agenReservDTO = new HoraDisponibleDTO();
			idMovimiento = (stmt.getInt(10)); 		
			agenReservDTO.setIdAgendaReserva(String.valueOf(idMovimiento));
			listAgenda.add(agenReservDTO);
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getAgendaEntidad SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}
	
	public List<HoraDisponibleDTO> setAgendaReservaRA(ReservaVORA resVO) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		/*
		System.out.println("reservaDAO");
		System.out.println("prg "+resVO.getIdAgendaPrg()+" pac:"+resVO.getIdPaciente()+" cant:"+
				resVO.getCantHoras()+" urg:"+resVO.getUrgenteSN()+" tipo:"+resVO.getIdTipoPac()+" user:"+resVO.getIdUser()+" ser:"+
				resVO.getIdServicio()+" obs:"+resVO.getObservacion()+" conf:"+resVO.getConfReag());
				*/

		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    						    
		int idMovimiento = 0;

		List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.setAgendaReserva(?,?,?,?,?,?,?,?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, resVO.getIdAgendaPrg());
			stmt.setString(2, resVO.getIdPaciente());
			stmt.setString(3, resVO.getCantHoras());
			stmt.setString(4, resVO.getUrgenteSN());
			stmt.setString(5, resVO.getIdTipoPac());
			stmt.setString(6, resVO.getIdUser());
			stmt.setString(7, resVO.getIdServicio());
			stmt.setString(8, resVO.getObservacion());
			stmt.setString(9, "");
			stmt.registerOutParameter(10, OracleTypes.INTEGER);					
			stmt.execute();
			HoraDisponibleDTO agenReservDTO = new HoraDisponibleDTO();
			idMovimiento = (stmt.getInt(10)); 		
			agenReservDTO.setIdAgendaReserva(String.valueOf(idMovimiento));
			listAgenda.add(agenReservDTO);
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getAgendaEntidad SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}		

	public List<ReservaDTO> getReservaByPac(String idPac, String idReserva) throws SQLException, IOException{
		Connection conn = ConexionPool.getConnectionPool();	
		List<ReservaDTO> listAgenda = new ArrayList<ReservaDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.getReservaByPac(?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, idPac);
			stmt.setString(2, idReserva);
			stmt.registerOutParameter(3, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(3);

			while (rs.next()) {
				//Datos de reserva
				ReservaDTO comDTO = new ReservaDTO();
				comDTO.setIdAgendaReserva(rs.getString(1));
				comDTO.setIdAgendaPrg(rs.getString(2));
				comDTO.setFecCita(rs.getString(3));
				comDTO.setHoraCita(rs.getString(4));
				comDTO.setNumHrs(rs.getString(5));
				comDTO.setEspecialidad(rs.getString(6));
				comDTO.setMedico(rs.getString(7));
				comDTO.setUrgente(rs.getString(8));
				comDTO.setPrestacion(rs.getString(9));
				comDTO.setFecRegistro(rs.getString(10));
				comDTO.setUsuarioIngreso(rs.getString(11));
				comDTO.setTipoAtencion(rs.getString(12));
				    //-- Confirmacion
				comDTO.setConfirmado(rs.getString(13));
				comDTO.setFecConfirmacion(rs.getString(14));
				comDTO.setUsuarioConfirmacion(rs.getString(15));
				comDTO.setObsConfirmado(rs.getString(16));
				    //-- Recepcion
				comDTO.setAsistencia(rs.getString(17));
				comDTO.setHoraAsistencia(rs.getString(18));
				comDTO.setUsuarioAsistencia(rs.getString(19));
				    //-- Atencion
				comDTO.setAtencion(rs.getString(20));
				comDTO.setHoraAtencion(rs.getString(21));
				    //-- Cancelacion
				comDTO.setFecCancelacion(rs.getString(22));
				comDTO.setMotivoCancelacion(rs.getString(23));
				comDTO.setObsCancelacion(rs.getString(24));
				comDTO.setUsuarioCancelacion(rs.getString(25));
				comDTO.setImgConfirmado(rs.getString(26));
				comDTO.setImgAsistencia(rs.getString(27));
				comDTO.setImgAtencion(rs.getString(28));
				comDTO.setRutdvPac(rs.getString(29));
				comDTO.setPaciente(rs.getString(30));
				comDTO.setIdSiglaProducto(rs.getString(31));
				comDTO.setIdArea(rs.getString(32));
				comDTO.setIdPreparacion(rs.getString(33));
				
				comDTO.setObsReserva(rs.getString(34));
				comDTO.setStrPreparacion(rs.getString(35));
				comDTO.setIdServicio(rs.getString(36));
				listAgenda.add(comDTO);
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getReservaByPac SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}	

	// fecha=De la semana acual; next=Semana anterior o posterior
	public List<ReservaDTO> getNextSemana(String fecha, String next) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    						    

		List<ReservaDTO> listAgenda = new ArrayList<ReservaDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.getNextSemana(?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, fecha);
			stmt.setString(2, next);
			stmt.registerOutParameter(3, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(3);

			while (rs.next()) {
				ReservaDTO comDTO = new ReservaDTO();
				comDTO.setFecCita(rs.getString(1));
				listAgenda.add(comDTO);
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getNextSemana SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}	

	public List<ReservaDTO> getSobreCupo(String idAgendaPrg) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    					    

		List<ReservaDTO> listAgenda = new ArrayList<ReservaDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.getSobreCupo(?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, idAgendaPrg);
			stmt.registerOutParameter(2, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(2);

			while (rs.next()) {
				ReservaDTO comDTO = new ReservaDTO();
				comDTO.setNumHrs(rs.getString(1));
				listAgenda.add(comDTO);
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getSobreCupo SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}	
	
	public List<HoraDisponibleDTO> setSobreCupo(ReservaVO resVO) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    						    

		List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.setSobreCupo(?,?,?,?,? ,?,?,?)}";

			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, resVO.getIdAgendaPrg());
			stmt.setString(2, resVO.getIdPaciente());
			stmt.setString(3, resVO.getIdTipoPac());
			stmt.setString(4, resVO.getIdUser());
			stmt.setString(5, resVO.getIdServicio());
			stmt.setString(6, resVO.getObservacion());
			stmt.setString(7, resVO.getIdAgReserv());
			stmt.registerOutParameter(8, OracleTypes.VARCHAR);
			stmt.execute();
			HoraDisponibleDTO agenReservDTO = new HoraDisponibleDTO();
			//horaReserva = (stmt.getString(5)); 		
			agenReservDTO.setHoraCita(stmt.getString(8));
			listAgenda.add(agenReservDTO);
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.setSobreCupo SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}

	public List<HoraDisponibleDTO> getServicioHora(String idServicio, String idPac) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    				

		List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
		try {
			String query = "{ call "+pkgVar+".PKG_THO_RESERVA.getServicioHora(?,?,?)}";

			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, idServicio);
			stmt.setString(2, idPac);
			stmt.registerOutParameter(3, OracleTypes.VARCHAR);
			stmt.execute();
			HoraDisponibleDTO agenReservDTO = new HoraDisponibleDTO();
			//horaReserva = (stmt.getString(5)); 		
			agenReservDTO.setCantHrs(stmt.getString(3));
			listAgenda.add(agenReservDTO);
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getServicioHora SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listAgenda;
	}
	
	public List<ListaUrgenteDTO> getListaUrg(String prof, String hrsDispo, String idArea, String idSede) throws SQLException, IOException{
		
		Connection conn = ConexionPool.getConnectionPool();	
				    
		List<ListaUrgenteDTO> listHrs = new ArrayList<ListaUrgenteDTO>();
		try {
			String query = "{ call "+pkgVar+".Pkg_tho_reserva.getListaUrgente(?,?,?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, prof);
			stmt.setString(2, hrsDispo);
			stmt.setString(3, idArea);
			stmt.setString(4, idSede);
			stmt.registerOutParameter(5, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(5);			
            while (rs.next()) {
            	ListaUrgenteDTO lista = new ListaUrgenteDTO();
               	lista.setMedico(rs.getString(1));
               	lista.setFecCita(rs.getString(2));
               	lista.setNumHoraCita(rs.getString(3));
               	lista.setPaciente(rs.getString(4));
               	lista.setRut(rs.getString(5));
               	lista.setFijo(rs.getString(6));
               	lista.setMovil(rs.getString(7));
               	lista.setTelefonos(rs.getString(6));//+" - "+rs.getString(7));
               	lista.setFecRegistro(rs.getString(8));
               	lista.setHrsDisponibles(rs.getString(9));
               	lista.setIdAgProg(rs.getString(10));
               	lista.setIdProf(rs.getString(11));
               	lista.setIdTipAt(rs.getString(12));
               	lista.setCantHorReserv(rs.getString(13));
               	lista.setIdPrest(rs.getString(14));
               	lista.setDescPrest(rs.getString(15));
               	lista.setIdPac(rs.getString(16));
               	lista.setIdAgReser(rs.getString(17));
               	lista.setDescTipAt(rs.getString(18)); 
               	listHrs.add(lista);
               	
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getListaUrgente SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listHrs;		
	}		
	public  List<ListaUrgenteDTO> getHoraCercana(String prof) throws SQLException, IOException{
		Connection conn = ConexionPool.getConnectionPool();	
		List<ListaUrgenteDTO> listHrs = new ArrayList<ListaUrgenteDTO>();
		try {
			String query = "{ call "+pkgVar+".Pkg_tho_rangos_agenda.getHoraCercana(?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, prof);
			stmt.registerOutParameter(2, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(2);			
	        while (rs.next()) {
	           	ListaUrgenteDTO lista = new ListaUrgenteDTO();
	           	lista.setNumHoraCita(rs.getString(1));
	           	listHrs.add(lista);
	           	
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error RangosAgendaDAO.getHoraCercana SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		}  finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listHrs;		
	}	
	public  List<ListaUrgenteDTO> getCitasList(String prof, String fecCitaActual) throws SQLException, IOException{
		Connection conn = ConexionPool.getConnectionPool();	  
		List<ListaUrgenteDTO> listHrs = new ArrayList<ListaUrgenteDTO>();
		try {
			String query = "{ call "+pkgVar+".Pkg_tho_reserva.getListHorUrg(?,?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, prof);
			stmt.setString(2, fecCitaActual);
			stmt.registerOutParameter(3, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(3);			
	        while (rs.next()) {
	        	ListaUrgenteDTO lista = new ListaUrgenteDTO();
	           	lista.setFecCita(rs.getString(1));
	           	lista.setIdAgProg(rs.getString(2));
	           	listHrs.add(lista);
	           	
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ReservaDAO.getCitasList SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);

		}
		return listHrs;		
	}	
	
	 public  List<CtrlMedicaDTO> getCitaByIDPAC(String idPAC) throws SQLException, IOException{
		 Connection conn = ConexionPool.getConnectionPool();	      
			List<CtrlMedicaDTO> listAgenPAC = new ArrayList<CtrlMedicaDTO>();
			try {
				String query = "{ call "+pkgVar+".Pkg_tho_agenda_reserv.getCitaByIDPAC(?,?) }"; 	       
				CallableStatement  stmt = conn.prepareCall(query);
				stmt.setString(1, idPAC);							
				stmt.registerOutParameter(2, OracleTypes.CURSOR);
				stmt.execute();
				ResultSet rs = (ResultSet)stmt.getObject(2);
				while (rs.next()) {
					CtrlMedicaDTO citaPacDTO = new CtrlMedicaDTO();
					citaPacDTO.setIdAgendaReserv(rs.getString(1));
					citaPacDTO.setIdAgendaPrg(rs.getString(2));
					citaPacDTO.setAsistenciaSN(rs.getString(3));
					citaPacDTO.setRechazoProfAR(rs.getString(4));
					citaPacDTO.setConfirmadoSN(rs.getString(5));
					citaPacDTO.setCantHorasReservada(rs.getString(6));
					citaPacDTO.setIdHistorialCanc(rs.getString(7));
					citaPacDTO.setFecCita(rs.getString(8));
					citaPacDTO.setHoraCita(rs.getString(9));
					citaPacDTO.setNombreProfesional(rs.getString(10));
					listAgenPAC.add(citaPacDTO);
				}
				rs.close();
				stmt.close();
			} catch (SQLException ex) {  
				log.error("Error ReservadaDAO.getCitaByIDPAC SQLException: " +ex.getMessage());
				System.out.println(ex.getMessage());
			} finally {
				conn.close();
				conn = null;
			}
			return listAgenPAC;	
	 }	
	
}
